package com.googlecode.sparda.commons.util;

import java.text.DecimalFormat;

/**
 * A Simple percentage format.
 * @author Fabio Grucci (<i>alias</i> <b>Phoenix</b>)
 * @see Percentager
 */
public class SimplePercentageFormat implements PercentageFormat {

	/**
	 * The decimal format used to represent the percentage.
	 */
	private final DecimalFormat percentageFormat;
	
	/**
	 * Build a simple percentage format.
	 */
	public SimplePercentageFormat() {
		this(new DecimalFormat("##.##%"));
		this.setDefaultPercentageFormatProperties();
	}
	/**
	 * Build a {@link SimplePercentageFormat} with a {@link DecimalFormat} to format the percentage.
	 * @param percentageFormat the {@link DecimalFormat} to format the percentage
	 */
	public SimplePercentageFormat(DecimalFormat percentageFormat) {
		this.percentageFormat = percentageFormat;
    }
	/*
	 * (non-Javadoc)
	 * @see com.googlecode.sparda.commons.util.PercentageFormat#format(double, int, int)
	 */
	@Override
	public String format(double percentage, int currenStep, int totalStepCount) {
		return this.percentageFormat.format(percentage) + " (" + currenStep + "/" + totalStepCount + ")";
	}
	
	/**
	 * Method that set default configuration for the default format ({@link SimplePercentageFormat}).
	 */
	protected void setDefaultPercentageFormatProperties() {
		this.percentageFormat.setGroupingSize(3);
//		this.format.setGroupingUsed(true);
	}

}
